package com.rs.admin.common.exception;

import com.rs.common.exception.BaseGlobalExceptionHandler;
import com.rs.common.exception.RRException;
import com.rs.common.utils.result.R;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.util.Set;

/**
 * 全局异常处理
 * @author hedonglin
 * @company 睿思科技
 * @email 1048791780@qq.com
 * @date 2017年12月21
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler extends BaseGlobalExceptionHandler{
    private static Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * shrio异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public R handleException(AuthorizationException e) {

        // you could return a 403 here instead (this is how github handles 403, so the user does NOT know there is a
        log.debug("AuthorizationException was thrown", e);

        //未授权信息回显
        return R.error(HttpStatus.FORBIDDEN.value(),"没有访问权限");
    }
}
